#!/usr/bin/env bash

set -e
cd "$(dirname "$0")/.."
source script/_common

rspec_args=()

for arg in "$@"
do
  rspec_args+=("${arg#updater/}")
done

# Check if we are in a CI environment
if [ -z "$CI" ]; then
  docker_run_args="-it"
else
  docker_run_args=""
fi

# Previously the updater image contained all ecosystems. Now the ecosystems are broken apart,
# but we still have some tests that need to run against other ecosystems. So by mounting the
# other ecosystems with -v into the updater image we can still run those tests.
script/build bundler

# shellcheck disable=SC2086
docker run --env DEPENDABOT_TEST_ACCESS_TOKEN \
  $docker_run_args \
  --pull never \
  --env VCR \
  --rm \
  -v "$(pwd)/updater/spec/fixtures/vcr_cassettes:/home/dependabot/dependabot-updater/spec/fixtures/vcr_cassettes" \
  "ghcr.io/dependabot/dependabot-updater-bundler:latest" bundle exec rspec "${rspec_args[@]}"
